/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package astroLib;

/**
 *
 * @author mehmetrg
 */
public class TimesKerahat {
    private TimeForSunAngle israkIsfirar,fajr,magrib,asrH;
    private double MJD0h, longitude, latitude;
    public TimesKerahat ()
    {  
        this(39.95*Math.PI/180,32.85*Math.PI/180,2.0,2008,3,11);
        
    }
    public TimesKerahat ( double latitude,double longitude, double timeZone,int year,int month,int day)
    {
        this.latitude=latitude;
        this.longitude=longitude;
      
        MJD0h=APC_Time.Mjd(year,month,day,0,0,0) - timeZone/24;       
        israkIsfirar=new TimeForSunAngle (5, MJD0h, longitude, latitude);
       
      
    }
    public TimesKerahat (EarthPosition earth,  double MJD0h)
    {
        this.latitude=earth.getLatitude();
        this.longitude=earth.getLongitude();
        this.MJD0h= MJD0h; 
        israkIsfirar=new TimeForSunAngle (5, MJD0h, longitude, latitude);
        magrib= new TimeForSunAngle (-1, MJD0h, longitude, latitude);
        fajr= new TimeForSunAngle (-18, MJD0h, longitude, latitude);
      
    }
    public double getIsrakTime (int temkin)
    {
       // System.out.println(APC_Time.Time(israkIsfirar.getRiseTime()+temkin/60.0));
        return israkIsfirar.getRiseTime()+temkin/60.0;
    }
    public double getIstivaTime ()
    { 
       // magrib= new TimeForSunAngle (-1, MJD0h, longitude, latitude);
      //  fajr= new TimeForSunAngle (-18, MJD0h, longitude, latitude);

        //System.out.println(APC_Time.Time((magrib.getSetTime()+fajr.getRiseTime())/2));
        return (magrib.getSetTime()+fajr.getRiseTime())/2;
    }
    public double getIsfirarTime ()
    {  
        //System.out.println(APC_Time.Time(israkIsfirar.getSetTime()));
        return israkIsfirar.getSetTime();
    }
    public double getDuhaTime ()
    {
        //System.out.println(APC_Time.Time(israkIsfirar.getSetTime()));
        return (3*fajr.getRiseTime()+magrib.getSetTime())/4;
    }

    public double getAsrHanefiTime (int temkin)
        {

          double sinAltitude,altitude,cotAltitude,asrHanafiAngle;
          TimeForSunAngle sunRise;
          sunRise= new TimeForSunAngle (-50.0/60.0, MJD0h, longitude, latitude);// Sunrise               at h=-50'
          sinAltitude=sunRise.getSinAltitudeForMidday();
          altitude=MATH.asin(sinAltitude);	/* Radians	*/
          cotAltitude= 1.0 / Math.tan(altitude);
          asrHanafiAngle= Math.toDegrees(Math.PI/2 - MATH.atan2((2.0 + cotAltitude), 1.0));
          asrH=new TimeForSunAngle (asrHanafiAngle, MJD0h, longitude, latitude)  ;
             //System.out.println(APC_Time.Time(asrH.getSetTime()+temkin/60.0));
          return asrH.getSetTime()+temkin/60.0;
        }
}

